import {
  addCarousel,
  getCarousels,
  removeCarousel,
  updateCarouselStatus
} from '@/service/main/setting/setting'
import { defineStore } from 'pinia'
import type { ISettingState } from './type'
const useSettingStore = defineStore('setting', {
  state: (): ISettingState => ({
    carouselTotalCount: 0,
    carouselList: []
  }),
  actions: {
    async addCarouselAction(insertInfo: any) {
      await addCarousel(insertInfo)
      this.getCarouselsAction()
    },
    async removeCarouselAction(carousel_id: number, queryInfo: any) {
      await removeCarousel(carousel_id)
      this.getCarouselsAction(queryInfo)
    },
    async updateCarouselStatusAction(carousel_id: number, status: string) {
      await updateCarouselStatus(carousel_id, status)
    },
    async getCarouselsAction(queryInfo?: any) {
      const carouselListResult = await getCarousels(queryInfo)
      const { totalCount, list } = carouselListResult.data
      this.carouselTotalCount = totalCount
      this.carouselList = list
    }
  }
})

export default useSettingStore
